package com.example.timeplanning_teacher;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class TaskActivity extends AppCompatActivity {

    private String content,subject,start_day,end_day,type;
    private int start_time,end_time,TaskId;
    private TextView title,Subject,StartDay,EndDay,Type,StartTime,EndTime;
    private Toast Success;
    private Toast Failure;
    private Toast timeOut_Toast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task);

        Success  = Toast.makeText(TaskActivity.this,"成功",Toast.LENGTH_SHORT);
        Failure = Toast.makeText(TaskActivity.this,"失败",Toast.LENGTH_SHORT);
        timeOut_Toast = Toast.makeText(TaskActivity.this, "网络连接超时", Toast.LENGTH_SHORT);

        Bundle bundle = getIntent().getExtras();
        SerializableMap serializableMap = (SerializableMap) bundle.get("map");
        content = (String) serializableMap.getMap().get("content");
        subject = (String) serializableMap.getMap().get("subject");
        start_day = (String) serializableMap.getMap().get("start_day");
        end_day = (String) serializableMap.getMap().get("end_day");
        type = (String) serializableMap.getMap().get("type");
        start_time = (int) serializableMap.getMap().get("start_time");
        end_time = (int) serializableMap.getMap().get("end_time");
        TaskId = (int) serializableMap.getMap().get("task_id");
        getId();
        title.setText(content);
        Subject.setText(subject);
        StartDay.setText(start_day);
        EndDay.setText(end_day);
        Type.setText(type);
        StartTime.setText(judgeTime(start_time));
        EndTime.setText(judgeTime(end_time));
    }

    private String judgeTime(int time){
        switch (time){
            case 0:
                return "6:00";
            case 1:
                return "6:30";
            case 2:
                return "7:00";
            case 3:
                return "7:30";
            case 4:
                return "8:00";
            case 5:
                return "8:30";
            case 6:
                return "9:00";
            case 7:
                return "9:30";
            case 8:
                return "10:00";
            case 9:
                return "10:30";
            case 10:
                return "11:00";
            case 11:
                return "11:30";
            case 12:
                return "12:00";
            case 13:
                return "12:30";
            case 14:
                return "13:00";
            case 15:
                return "13:30";
            case 16:
                return "14:00";
            case 17:
                return "14:30";
            case 18:
                return "15:00";
            case 19:
                return "15:30";
            case 20:
                return "16:00";
            case 21:
                return "16:30";
            case 22:
                return "17:00";
            case 23:
                return "17:30";
            case 24:
                return "18:00";
            case 25:
                return "18:30";
            case 26:
                return "19:00";
            case 27:
                return "19:30";
            case 28:
                return "20:00";
            case 29:
                return "20:30";
            case 30:
                return "21:00";
            case 31:
                return "21:30";
            case 32:
                return "22:00";
            case 33:
                return "22:30";
            case 34:
                return "23:00";
            default:
                return "err";
        }
    }

    private void getId(){
        title=findViewById(R.id.TaskTitle);
        Subject=findViewById(R.id.subject);
        StartDay=findViewById(R.id.startDay);
        EndDay = findViewById(R.id.endDay);
        Type= findViewById(R.id.type);
        StartTime = findViewById(R.id.startTime);
        EndTime= findViewById(R.id.endTime);
    }

    public void PassThis(View v){
        PassSingleThread passSingleThread = new PassSingleThread(TaskId,Success,Failure,timeOut_Toast);
        passSingleThread.start();
        Intent intent = new Intent(TaskActivity.this,FragmentActivity.class);
        TaskActivity.this.finish();
    }

    //左上角返回键，其他页面相同
    public void backviewonClick(View view) {
        TaskActivity.this.finish();
        overridePendingTransition(R.anim.no_anim, R.anim.trans_out);
    }

    //重写手机返回键，添加切换动画，其他页面相同
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            TaskActivity.this.finish();
            overridePendingTransition(R.anim.no_anim, R.anim.trans_out);
        }
        return super.onKeyUp(keyCode, event);
    }

}